package cn.ibizlab.odoo.core.odoo_web_editor.service.impl;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.HashMap;
import java.math.BigInteger;
import java.util.Collection;

import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cglib.beans.BeanCopier;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import cn.ibizlab.odoo.core.client.model.Iweb_editor_converter_test;
import cn.ibizlab.odoo.core.odoo_web_editor.domain.Web_editor_converter_test;
import cn.ibizlab.odoo.core.odoo_web_editor.filter.Web_editor_converter_testSearchContext;
import cn.ibizlab.odoo.core.odoo_web_editor.service.IWeb_editor_converter_testService;
import cn.ibizlab.odoo.util.SearchResult;
import cn.ibizlab.odoo.util.log.IBIZLog;

/**
 * 实体[Web编辑器转换器测试] 服务对象接口实现
 */
@Slf4j
@IBIZLog
@Service
public class Web_editor_converter_testServiceImpl implements IWeb_editor_converter_testService {

    @Autowired
    private cn.ibizlab.odoo.core.client.service.Iweb_editor_converter_testClientService web_editor_converter_testClientService;

    @Override
    public boolean create(Web_editor_converter_test web_editor_converter_test) {
        boolean bOk = false ;
        Iweb_editor_converter_test clientModel = this.convert2Model(web_editor_converter_test,null);
        web_editor_converter_testClientService.create(clientModel) ;
        this.convert2Domain(clientModel,web_editor_converter_test);
        bOk = true ;

        return bOk ;
    }

    @Override
    public void removeBatch(Collection<? extends Serializable> idList, int batchSize) {

        //web_editor_converter_testClientService.removeBatch(web_editor_converter_tests) ;

    }

    @Override
    public Web_editor_converter_test get(Integer id) {
        Iweb_editor_converter_test clientModel = web_editor_converter_testClientService.createModel();
        clientModel.setId(id);
        web_editor_converter_testClientService.get(clientModel) ;
        return this.convert2Domain(clientModel,null);
    }

    @Override
    public Web_editor_converter_test get(Web_editor_converter_test web_editor_converter_test) {
        Web_editor_converter_test retweb_editor_converter_test = this.get(web_editor_converter_test.getId()) ;
    	BeanCopier copier=BeanCopier.create(retweb_editor_converter_test.getClass(), web_editor_converter_test.getClass(), false);
        copier.copy(retweb_editor_converter_test, web_editor_converter_test, null);
        return web_editor_converter_test ;
    }

    @Override
    public void createBatch(List<Web_editor_converter_test> web_editor_converter_tests, int batchSize) {

                        //web_editor_converter_testClientService.createBatch(web_editor_converter_tests,batchSize) ;

    }

    @Override
    public boolean remove(Integer id) {
        boolean bOk = false ;
        Iweb_editor_converter_test clientModel = web_editor_converter_testClientService.createModel();
        clientModel.setId(id);
        web_editor_converter_testClientService.remove(clientModel) ;
        bOk = true ;
        return bOk ;
    }

    @Override
    public void updateBatch(List<Web_editor_converter_test> web_editor_converter_tests, int batchSize) {

        //web_editor_converter_testClientService.updateBatch(web_editor_converter_tests,batchSize) ;

    }

    @Override
    public boolean update(Web_editor_converter_test web_editor_converter_test) {
        boolean bOk = false ;
        Iweb_editor_converter_test clientModel = this.convert2Model(web_editor_converter_test,null);
        web_editor_converter_testClientService.update(clientModel) ;
        this.convert2Domain(clientModel,web_editor_converter_test) ;
        bOk = true;
        return bOk ;
    }

    /**
     * 查询集合 默认查询
     */
    @Override
    public Page<Web_editor_converter_test> searchDefault(Web_editor_converter_testSearchContext context) {
        List<Web_editor_converter_test> list = new ArrayList<Web_editor_converter_test>();
        Page<cn.ibizlab.odoo.core.client.model.Iweb_editor_converter_test> clientModelList = web_editor_converter_testClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Iweb_editor_converter_test clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Web_editor_converter_test>(list, context.getPageable(), clientModelList.getTotalElements());
    }


    /**
     * 根据用户查询
     */
    @Override
    public Page<Web_editor_converter_test> selectByOdoo_create(Integer id){
        Web_editor_converter_testSearchContext context = new Web_editor_converter_testSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Web_editor_converter_test> list = new ArrayList<Web_editor_converter_test>();
        Page<cn.ibizlab.odoo.core.client.model.Iweb_editor_converter_test> clientModelList = web_editor_converter_testClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Iweb_editor_converter_test clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Web_editor_converter_test>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据用户查询
     */
    @Override
    public Page<Web_editor_converter_test> selectByOdoo_write(Integer id){
        Web_editor_converter_testSearchContext context = new Web_editor_converter_testSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Web_editor_converter_test> list = new ArrayList<Web_editor_converter_test>();
        Page<cn.ibizlab.odoo.core.client.model.Iweb_editor_converter_test> clientModelList = web_editor_converter_testClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Iweb_editor_converter_test clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Web_editor_converter_test>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据Web编辑器转换器子测试查询
     */
    @Override
    public Page<Web_editor_converter_test> selectByOdoo_many2one(Integer id){
        Web_editor_converter_testSearchContext context = new Web_editor_converter_testSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Web_editor_converter_test> list = new ArrayList<Web_editor_converter_test>();
        Page<cn.ibizlab.odoo.core.client.model.Iweb_editor_converter_test> clientModelList = web_editor_converter_testClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Iweb_editor_converter_test clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Web_editor_converter_test>(list, context.getPageable(), clientModelList.getTotalElements());

    }



    public Iweb_editor_converter_test convert2Model(Web_editor_converter_test domain , Iweb_editor_converter_test model) {
        if(domain == null)
            return model ;
        if(model==null){
            model = web_editor_converter_testClientService.createModel() ;
        }

         if(domain.getTextDirtyFlag())
            model.setText(domain.getText());
         if(domain.getCreate_dateDirtyFlag())
            model.setCreate_date(domain.getCreate_date());
         if(domain.getSelection_strDirtyFlag())
            model.setSelection_str(domain.getSelection_str());
         if(domain.getNumericDirtyFlag())
            model.setNumeric(domain.getNumeric());
         if(domain.getIntegerDirtyFlag())
            model.setInteger(domain.getInteger());
         if(domain.getBinaryDirtyFlag())
            model.setBinary(domain.getBinary());
         if(domain.getDateDirtyFlag())
            model.setDate(domain.getDate());
         if(domain.getIbizfloatDirtyFlag())
            model.setIbizfloat(domain.getIbizfloat());
         if(domain.get__last_updateDirtyFlag())
            model.set__last_update(domain.get__last_update());
         if(domain.getDatetimeDirtyFlag())
            model.setDatetime(domain.getDatetime());
         if(domain.getIdDirtyFlag())
            model.setId(domain.getId());
         if(domain.getWrite_dateDirtyFlag())
            model.setWrite_date(domain.getWrite_date());
         if(domain.getHtmlDirtyFlag())
            model.setHtml(domain.getHtml());
         if(domain.getDisplay_nameDirtyFlag())
            model.setDisplay_name(domain.getDisplay_name());
         if(domain.getIbizcharDirtyFlag())
            model.setIbizchar(domain.getIbizchar());
         if(domain.getSelectionDirtyFlag())
            model.setSelection(domain.getSelection());
         if(domain.getCreate_uid_textDirtyFlag())
            model.setCreate_uid_text(domain.getCreate_uid_text());
         if(domain.getWrite_uid_textDirtyFlag())
            model.setWrite_uid_text(domain.getWrite_uid_text());
         if(domain.getMany2one_textDirtyFlag())
            model.setMany2one_text(domain.getMany2one_text());
         if(domain.getWrite_uidDirtyFlag())
            model.setWrite_uid(domain.getWrite_uid());
         if(domain.getMany2oneDirtyFlag())
            model.setMany2one(domain.getMany2one());
         if(domain.getCreate_uidDirtyFlag())
            model.setCreate_uid(domain.getCreate_uid());
        return model ;
    }

    public Web_editor_converter_test convert2Domain( Iweb_editor_converter_test model ,Web_editor_converter_test domain) {
        if(model == null)
            return domain ;
        if(domain == null){
            domain = new Web_editor_converter_test();
        }

        if(model.getTextDirtyFlag())
            domain.setText(model.getText());
        if(model.getCreate_dateDirtyFlag())
            domain.setCreate_date(model.getCreate_date());
        if(model.getSelection_strDirtyFlag())
            domain.setSelection_str(model.getSelection_str());
        if(model.getNumericDirtyFlag())
            domain.setNumeric(model.getNumeric());
        if(model.getIntegerDirtyFlag())
            domain.setInteger(model.getInteger());
        if(model.getBinaryDirtyFlag())
            domain.setBinary(model.getBinary());
        if(model.getDateDirtyFlag())
            domain.setDate(model.getDate());
        if(model.getIbizfloatDirtyFlag())
            domain.setIbizfloat(model.getIbizfloat());
        if(model.get__last_updateDirtyFlag())
            domain.set__last_update(model.get__last_update());
        if(model.getDatetimeDirtyFlag())
            domain.setDatetime(model.getDatetime());
        if(model.getIdDirtyFlag())
            domain.setId(model.getId());
        if(model.getWrite_dateDirtyFlag())
            domain.setWrite_date(model.getWrite_date());
        if(model.getHtmlDirtyFlag())
            domain.setHtml(model.getHtml());
        if(model.getDisplay_nameDirtyFlag())
            domain.setDisplay_name(model.getDisplay_name());
        if(model.getIbizcharDirtyFlag())
            domain.setIbizchar(model.getIbizchar());
        if(model.getSelectionDirtyFlag())
            domain.setSelection(model.getSelection());
        if(model.getCreate_uid_textDirtyFlag())
            domain.setCreate_uid_text(model.getCreate_uid_text());
        if(model.getWrite_uid_textDirtyFlag())
            domain.setWrite_uid_text(model.getWrite_uid_text());
        if(model.getMany2one_textDirtyFlag())
            domain.setMany2one_text(model.getMany2one_text());
        if(model.getWrite_uidDirtyFlag())
            domain.setWrite_uid(model.getWrite_uid());
        if(model.getMany2oneDirtyFlag())
            domain.setMany2one(model.getMany2one());
        if(model.getCreate_uidDirtyFlag())
            domain.setCreate_uid(model.getCreate_uid());
        return domain ;
    }


}
